﻿<ControlTemplate 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:std="clr-namespace:Standard"
    TargetType="{x:Type Window}">
  <!-- Template to use when the Window's chrome is gone.
         This is generally similar to the standard Window template, 
         but it allows drawing everywhere on the client. -->

  <!--
     Create the Canvas with dimensions that span the full size of the Window.
     Window's implementation of ArrangeOverride does some extra work to accomodate
     for the standard chrome and RTL when FlowLayout="RightToLeft".
     By binding to ActualWidth/ActualHeight we avoid the impact of the AdjustWindowRectEx call,
     but to correctly handle RTL we need to apply the transform ourselves.
     BUGBUG: The first render in the RTL case is wrong.  Resizing fixes it.  I could just poke
         it the first time to get it to update, but I want to understand what's happening so 
         I'm leaving the behavior. -->
  <Canvas x:Name="PART_RootCanvas"
          Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=ActualWidth}"
          Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=ActualHeight}">
    <Canvas.Style>
      <Style TargetType="{x:Type Canvas}">
        <Style.Triggers>
          <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=FlowDirection}" Value="RightToLeft">
            <Setter Property="RenderTransformOrigin" Value=".5, .5"/>
            <Setter Property="RenderTransform">
              <Setter.Value>
                <ScaleTransform ScaleX="-1"/>
              </Setter.Value>
            </Setter>
          </DataTrigger>
        </Style.Triggers>
      </Style>
    </Canvas.Style>
    <Border x:Name="PART_BackgroundBorder"
            Background="{TemplateBinding Background}"
            BorderBrush="{TemplateBinding BorderBrush}"
            BorderThickness="{TemplateBinding BorderThickness}"
            Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}, Path=Height}"
            Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}, Path=Width}"/>
    <AdornerDecorator x:Name="PART_Adorner"
            Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}, Path=Height}"
            Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Canvas}}, Path=Width}">
      <ContentPresenter/>
    </AdornerDecorator>
    <ResizeGrip HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="Collapsed" IsTabStop="False"/>
  </Canvas>
</ControlTemplate>
